Refactor scoring function out of the filtering function.