Avoid index out of bounds exceptions.