Chemistry of water treatment