sorting endpoints and making them unique