Refactored to remove one "if" statement.