moved out problem 20
much improved solution for problem 20