Refactored model and controller from server