Fixes to threading