Bugfixes: make sure variables that are used are set

Untested, but is more consistent with the variables used.