correct resource sorting function