improved upgrade routine