refactored build&upgrade