Refactored: Improved code for upgrading from older installations.