Cleaning up code for problem 1