add error handling for each thread