unify filename code into single function