Refactored the main sinatra loop to hopefully work