homework4 refactoring