completed code for HW 2