Added most of the code for problem 12.