refactoring & sorting csv rows