Bug fixes and cleanup.