Cleanup of answer to problem 1