added weighted version of the union algorithm