pulled in some changes from kx499's branch with Rule Search