Refactor some conditional statements