Fix upgrade functionality and associated tests