Advanced water and wastewater treatment