fix while len(handlebuffer)=0, handlebuffer[-1] exception in a simplest way