Added comparator to make frequencysorting possible.
Merged Sebastians filewriter.