Fixed logic surrounding invalid expressions.