Reorganize logic into smaller methods