fixed some logic in the read buffer, still not perfect.