changing logic of madd function