first working version of substitutor.  Compile and Valgrind clean.  Seems pretty fast.