Small defun to clean up the buffer before saving