fix offset out of bound bug