bugfix to bugfix: close tmp file before renaming it