Fix bug with buffer swapping