Terrible attempt at refactoring