make time function more efficient