improved problem 36 solution