Added method for validating expressions.