Fix main loop crash