Implements majority of controller.