Fixed error in time function