refactoring codes(hw1-3)