first stab at refactoring