Added if and for loop