fixed bugs with thread functions not being re-entrant