Refactored duplication in controller