Refactored cascading if-else.