Completed solution for problem 12