refactoring. fixing code duplication