Completed solution for homework 3.