Major improvements and bugfixes for upgradesystem