Fix reading with any buffer size

Fixed #7 and #8.