this was mostly just rearranging code in this controller to make it more read-able.