Updated computeNextZIndex procedure.