Fix for the use of the variables in the sources and a couple of other small changes.

Here is the previously discussed patch together with a couple of other small changes done while working on it.

I'd prefer to push this directly to master if you don't object instead of merging this as the 3 commits are not really related, so it's more of a request for review than a PR.