Move variable out of loop
Add else part to if statements