Fixed bugs in upgrade.