Updated upgrade code