Fixed null condition to ensure that null values get pushed back in the array.
replacing full array sort with a range sort