first rough version of new minpermdist before cleaning up mindist