How to exit a nested if statement