Code cleanup around the environment substitution steps