refactor to avoid foreach when filtering

It's a single line and it avoids the foreach and the loop conditional.