problem 3 solved, some stylistic changes to problem 2