add test procedure for csv export and some refactoring