Fix up thread code to Josh spec. and fix XLIB compile error.