fixed buffer size problem and a few small changes