Simplifying expressions and substitution