reorganized this large controller for readability