refine min max expected and fix some bugs