Finished code for 2nd assignment with comments