Fixing minmax algorithm