Templatize
Use R instead of string everywhere
Correct bug in decodeCxxSubstitution