fix buffer checking