Fix some out of bounds accesses