Problem 17, some rearranging