Don't allocate more buffer memory than we need.
Minor restructuring, no real change.
Don't step off the end of the allocated buffer.
Free memory when done.
Back off -s to 1Mb.