This appears to be working

but I'm probably about to break it again as I continue developing. Enjoy it while you can!
@Galithil and @mariogiov great work!!! with the new APIs this function is way easier to understand!!!