Refactor nested if

Small refactoring so that it avoids nested `if` statement.