Added computeNextZIndex procedure.