Fix errors in setup_upgrade
Other minor changes