Improved upgrading script.