major refactoring of rule application