attempt at refactoring