Refactoring and DRYing up controller code