worke on upgrade function