using stack space for buffers as per graham's suggestion