Rewrote as scala library, all old tests pass