added support for rules and substitutions