Improve file export logic.

#2