Added Error Handling for threads