Fix file name creation

Closes #1974 and #1975