Moved main loop back to main