this invention relates to systems for treating wastewater and more particularly to removing nutrients from wastewater in a wastewater treatment system . wastewater tanks , each having membrane filters , are arranged in series . each tank is equipped with respective inlets and outlets and an air supply as well as detectors for monitoring various wastewater parameters . a controller is coupled to the detectors , inlets and outlets for effecting sequences of opening and closing the inlets and outlets and turning the air supplies on and off in response to various detecting conditions and effects different operations , including a cleaning mode , in different cycles .