fix bugs related to buffer