lots of refactoring, moving stuff around