Fix out of bounds accesses