Second pass at implementing gremlin. Most of this is untested.