Duplication: added `indexGuard` and `emptyGuard` which throw exceptions when the check fails.