Added more testing for bad threads and bad replies
Simplified the code a bit