Moved key filtering

Key filtering moved before returning results