Fixed the race condition in aa36bef and cleared the buffer in 1c8fea2.