better buffer checking