You have a massive legacy spaghetti mess of code, and you need to add a new feature.
Write tests first.
Put all your new code in a new module, and only insert single lines into the legacy code to call the new code. This allows you to properly encapsulate the new code, wrap it in try/catch blocks, etc. and not break the legacy system.
Pass whole objects into the new code, this is a necessary consequence of encapsulation.