prevent index out of range