Added min distance to query