Refactoring cog_upgrade utility.