tinfoil patch: be more diligent about checking array boundaries before