Cleaned up Problem 3 solution.