fixing some errors and add event handler to buffer changed text