time function and improvements