improved error handling for nested if clauses