Finalized HW2 code