Fix for "Fails with no ungrouped categories"

I've wrapped the print statements for ungrouped categories with a conditional to check if the array is nil. This stops the error for sorting a nil array from occurring.

I've tried to keep it in the same style.