fixed bug in threading