Generalized connected sum construction for scalar flat metrics