Cleaned the main loop a bit