fix buffering issue. add logging