fix while len(handlebuffer)=0, handlebuffer[-1] exception