rearrange the if statements appropriately