Fix buffer handling, it wasn't tested at all anyway