improved logic for filtering notifications