Finished code for homework 5