This logic should be removed from here and added as part of the upgrade mechanism