Cleaned up the controller to combine the two loops into one