make temp file creation bit safer on platforms withouth mkstemps()
cleanup global variables