Wrote some of the algo.