Refactored enough to get tests working again.