Water management and wastewater purification