This fix required extra work than i was expecting. I ended up moving the split functionality into its own module because it's more involved than i expected. And to enable testing of the code, for which i addeed tests.