minor cleanup and bug fixes