Refactoring code.
Reversed sort order of columns according to habit.

Made automatic writing of output file optional.

Returns now a list instead of dataframe.