Consolidated some repetitious code in the controller.