move the filtering logic out of the parser