complete solution, one error in problem 13