refactoring, remove the duplicate code