Some minor cleaning up [ci skip].
Saving files: some work towards first saving to a temporary file and then overwrite the original file (#523) [ci skip].