Completed solution to assignment along with comments.