Corrected the sorting for the 'z' coordinate case