improved buffer implementation