Refactoring checks of overlapping conditions in if and else-if