Improve sorting by another array