Half way through tree rewriting of algorithm