Fix bug in upgrade script