Refactored code for finding minimum among indices.