cleaned up code and completed problem 13