hw4 small refactoring and tuning