added timeout code to thread code