Refactored duplicate code.