Pass baseFilename as an argument rather than a global.