finalized refactoring, added solution to hw4