Process optimisation and fouling control in membrane bioreactors for wastewater and drinking water treatment