Rules: Bug fixes and refactoring