improved problem 17
problem 22