Some more thread work, and some minor fixes.