Tweaks to export funciton to make it more robust and auto-detect saved fieldnames