Add out-of-bounds checking