Bug fixes and test cleanup.