This set of patches fixes errors seen in multithreaded environments and improves error reporting greatly