hw1 refactored