fix many bugs and add a part of nm xray refinement module