bunch of refactoring