Some fixes in the timeout code