Lots of refactoring in hw1 and hw2