Added category sorting.
Fixed newlines.
Formatted code with astyle.