trapping more errors and improving error reporting