fixed bug in deciding how large of a buffer to allocate