Move global variables.
Remove unneeded ifs