Cleaner code in upgrade.py