Improve rule checking, to fix panic Trac #4398