fixd min max index in main for-loop