Refactored nested if-statement.