minmax algorithm fixes