refine buffer handling