very slow refactoring to add room for rules