Cleanup and bug fixes.