started refactoring out a bit