Some fixes to the threading.