more write impl and fixed buffer_clear bug