Added more logic to the upgrade functionality