reduce a nested if statement