implemented improved filtering and much-simplified GetRate() function