Refactored into smaller code chunks