Minor optimization

Move loop invariant code.
Oops, meant: `excludes = Array.isArray(excludes) ? excludes : [];`