refactored controller logic into models