fixed index out of bound error