Corrected and cleaned code