Fixed up termination
Added timeout handling
Fixed up timeout code