Rearranged code to have a loop function for the controller that can be spawned into its own go routine