Added in Ian's fixed algorithm. Ian did a lot of the work in this branch so far.