hw4 part 1.9 with bug fixed