Fixed calculation of elapsed time