Haven't tried it, but this rewrite might be better?

https://github.com/Dicklesworthstone/beads_rust