Fix reading with any buffer size

Fixes #7 and #8.