Refactor using max_by method