Some of refactoring and lots of rules.
Some fixes.