Fix 2 problems: the version checking was broken and the sorting did not work in some cases.