This MR cleans up the z-clipping code to use a more elegant loop. Should fix a number of freezes and glitches.