refactoring export.py file