Added a unit test for rules, fixed an indexing bug.