Only exit command loop after all work is done