improve export script: better sorting