First whack at refactoring
Refactoring.