Fixing bug in time calculation