improved solution to problem 37