minor cleanup and bug fixes from code review