Improved if chain