added filterAndRank function