added support for tmpDir, using path module, cleanup