As someone just coming into this code, I have no idea what's happening here. I'd suggest adding JSDoc to the function and probably add more documentation into the flow here.