refactoring, remove duplicate code