Improve upgrade script