Move too-early assignment inside the if stmt where the var is actually used

This is a completely trivial (famous last words, I know...) optimization, moving an assignment inside an if statement where the variable is actually used.