implemented FreeScratch and AllocScratch