Some bugs on upgrade, and som code review