fix line index out of range error