fix buffering bugs