There are places where you are using `fn` for file-name (which is confusing wrt/ `function` IMHO) & others where you use `filename`.  Please rationalize.