upgrading algorithm