Extra condition needed to prevent out-of-bounds memory access