add array length check to comparison