Rewrote in Python, can't test yet