Substitution bug fixes