fixes and additions for threaded code