mainLoop: preventing hangup