refactore some codes of controller