First attempt at refactoring