small refactor of the nested if