I took a first look at this, and tied myself up in a pretzel. There are some rather complex loops here.
One approach is to pull only the bare dependencies of collections into scalar math, and then put everything else that isn't collections into vector-math. Some might prefer to see more things go into the scalar library. I might argue that starting with this approach and then doing a few extra shuffles is the way to go in any case.