refactored update time function