Change if statement short circuit execution

Potentially lengthy string checking and defindex exceptions are evaluated in nested if statement