Improving code duplication in controllers