Fix potential ReferenceError in non-browser env

Testing for `window` would throw if undeclared.
Also, avoid repeating feature check.