added a nested if