improve formatFilename function