Made a much simpler solution to problem 40.