refactoring and fixed csv format export