It might be worth refactoring this function by splitting it in at least two functions (one for csv, the other one for nrml). What do you think?