fixed upgrade code