This "object filtering" logic can be moved into its own method to avoid making this one more complex than it needs to be.