Fix crash when upgrading