Modify mondrian fuction

1 issue remain:
when all QI values are equal, my fuction will enter infinite loop