Fixed upgrade function