refactor file name & format resolution into function