refactored into smaller methods