more refactoring of controller and model
Merge branch 'refactor'