updated z-sorting