fixed an index out of bounds