Fixed some bugs in the export script