fixed upgrade function