Various bugfixes with tmp directory integration