Fixed bugs in scratch file naming