Huge-ass refactor.

(or a huge ass-refactor...)
throw an error if we cannot determine the latest version
some fixes