Added a closest_match function with dynamic fit