reorginize module migration. Add code for migration mode.