bug fix with reading from buffer