added a way to limit the buffer size