Finished problem 4 - Cleaned up code