Return from a mountain of ugly code
Fix issue with buffer attempting to replace itself