debugged the main code