better type sort + code formatting

Will also sort by name if categories match

Every once in a while I run it through jsbeautifier