fix sorting with null optional value

Fixes issue #324