slightly refactor solution to problem 35