fixed some bugs that prevented correct upgrades