Fix bug when scratch buffer does not exist