refactored duplicate code