added more code for HW3 part 3