Refactore groups controller.