modified for HW4 part2