Although this still looks quite messy, it should allow us to start splitting up this functionality in a more fine-grained way in the future. Specifically, the next step is to split off the way that the clip stack is handled, so that this can be done once during clip-scroll tree update - for performance reasons.