improve z sort