Move variable declarations, remove unneeded assignments, remove comparis...

...on duplication