Corrected main code