Added code for doing substitutions