I'm afraid I do not understand  your point again.
I imagine that you can enter in the first if-statement, modify variables and then you have to check the second if-statement with the previous values (err, ...).
What I can do is to delete the line test2 = ...

Is it what you want?