added check for temp directory before cleaning