Refactored into smaller methods