re-order codes to avoids a MVMROOT, and some cleanups