Optimized code, replaced repeat with filter