start complete refactoring to make it testable and extendable