refactor a bit of how matching works. added rules script.