Fix calculation of elapsed time in timeout()