Added some timeout handling

It is from here:

https://gist.github.com/mynameisfiber/2853066

but it doesn't seem to give me the perf I want.