Some refactoring and adding more rules.
More refactorings.