Misc. fixes for threads