Minor performance tweaks to apply-sub-to-term.
Added some new term-walk code to use restrictions. It's not fully tested yet, and thus not used.