fixing offset and using end sort