Improve location sorting

Adds optimisation to location minimum calculation and stores
location minimum information into CDS object.
Fix bug if there are no CDS found

The CDS sort should be caled only if CDS records are found.