Refactoring of controller