Fix logic of if statement