properly parse duplicates, sort by distance etc