Add tests for rule module
Fix bugs in rule module