New formatting of output file, some code cleanup