Finished code for assignment 2 with comments