Fixed bug where export would not write on first attempt for #4