Added conditional statement to perform logic for loops separately from conditionals