fixed bugs in threading
fixed bugs in threading