Fix critical bug with out-of-bounds collisions and writes