finished code for homework 1