Fixed a bug in time calculation