Bug fixes, code cleanup.