Fix the input buffering algorithm.

Signed-off-by: Matt Cleveland <mgcleveland@gmail.com>