routines for buffer management