Refactoring and fixing the model and controller.