Fix duplicate 'key' parameter when added as a parameter

I have discovered a case where if `key` is provided as a parameter, a duplicate value is created with the filename. The solution is to set the `key` parameter only if it is not present.