Fix nasty nested if/elif/else