mother of all refactors

It will be nice, if you approve my pull request