add sorted by function