Refactored uglier bits. Interface changes. Simplified some tests.