Updated sort

Refactored. Now works for id, name and content.