References to wrong variables

I had to change the code in these places to actually get this working.