First pass testing and refactoring.