Code cleanup in upgrade functions.