fixed possible array index out of bounds