Optimised code for z-index sorting of panes