added sorting for links queries, was breaking without them