Fixed spacing causing confusion around nested if statements

Is this the intended execution of those if statements? If not, it will need to be refactored with the 'fi' statements in the correct place.