code to deal with timeouts