Setup rules for filtering
Added pseudocode