Fixed bug causing export to terminate too early