Changed the substitution function so it doesn't recursively define a function.