fixing last sort bug