Fix bug that could result in infinite loops when exporting.