Refactored methods for easier testing