refactoring lots of stuff