a lot of refactoring here
Merge branch 'refactoring'