Better logic in the buffering thread loop