bug fixes, cleanup