Data tree restructuring based on clusters of non-null values

I have a data tree with 50 branches, and each branch has 50 values. Some of those values are null. I am looking to rearrange my tree structure so that I have clusters of consecutive non-null values in their own branch. See image attached for a better explanation. Any ideas how to achieve this?

branches.gh (7.8 KB)

Something like this?


branches_re.gh (10.4 KB)

That’s it, thanks! Nicely done.