Refactored parse_date code