refactored business logic into models.py