Added dynamic buffer size calculation and increased raw buffer size