fixed: now selects minimum