First step of refactoring.
Some more changes.
refactoring ready