a bunch of refactoring