Added consistent ordering of columns in output files. Still needs improved robustness. Minor refactoring and added test cases and files for new functions.