refactored extract_times function