KH-204: Sort collection before making comparsions for versions

Would otherwise randomly fail when checking whether code element is in
the latest codes.