Moved variable to if-statement