Prevent index out of bounds