Made requested changes with exception of the tmpfile() usage