Upgrade algorithm