Fix issues with sort on null or absent fields