Fix invalid index request to a set in get_context.
Rename variable shadowing a built-in
Double check that a file exists before stating during generation
Clean-up to fix some code inspection warnings