Finished HW2 code