refactoring removing code duplication