Sort by key function.