minor refactoring on timing function