Big code cleanup for variables and test fixes, ruleManager api changes