Possible bugfix

I'm not sure if this is the best way to solve the problem, but I get NameErrors unless I pull these variables outside the branch.