Fixed upgrade code