Fixed threading, and other minor fixes.