fixing some errors and add event handler to buffer change text