More minor refactoring. Still failing to complete.