refactoring: put more logic in model, less in controller