Changed main loop