Tidy up timeout and exception handling code