Fix index out of range panic.