fix some issues with tmp files

Fix some issues with tmp files... I hope I got this right.