refactored filtering as function, fixed misunderstood Scatter usage