I think this should go after the `err` check as `f` might be nil, resulting in a nil pointer panic.