Corrected main script and updated drainage functions