fix code rot
fixed bug in threading code