refine the buffer idx