add filter in raw stats, refactor code