Implemented exporting to CSV; also fixed bug causing crash if exporting
twice in a row