replace sort with sort_by

this is more idiomatic and generally faster