refactored models and controllers