Upgrade: Get back the checks before calling `upgrade`

Also did some cleanups to remove unnecessary code and polished code.