This definitely needs some documentation about what problem it's solving and why it needs to be done. It maybe doesn't need to go at the docstring level but a few inline comments would be good.