improved solutions to problem 2