Bug fixes, cleanup