refactoring codes(1-3)