Fixed bug for handling cases when |I| or |A| is zero.