That I don't know, I haven't deeply looked at the logic of the implementation. The first goal of this PR was to make just a remplacement to avoid global for the time being. I just they were nulled in the function so made them as parameters and return value not to change the behavior of the function at all.

This does not mean the logic could be simplified.

I'll take a look when I get more time.