Reimplemented 'latest_version()' to fix #12663 and make it more readable + better debug-able.

`latest_version' caused some trouble as outlined in #12663

Part of the problem was not using `versions_as_list=True` for retrieving the list of installed package (resulting in version strings of joined single versions like `15.0.4420.1017,15.0.4569.1506`), but also a bit convoluted implementation.

This re-implementation works fine for me, but a review + test would appreciated to make sure we don't break anything.