fixed potential problem in reading buffer, and tweaked parameters.