Fixes #368

Avoids the false positives listed in #368 and passes all tests.
`entities` is guaranteed to be an object with a length property, change to `if (entities.length) {`