Properly chain if and else when we are comparing to the same value so not to execute unnecessary comparisons.
mentioned in commit a28159ab