first stab at refactoring some of these changes