fix offset out of bound error