Make it work cross-platform.

More robust finding of the initial line

Sort results which have same distance alphabetically