Factor filename code into separate library.