Bugfix Sorting Algorithm

Added null object check before assignment.

Appears to be working now.