cleaned up the code for stage 1