performance improvements and tempdir improvement