Refactoring. TODO: use idx to identify the biggest elements