If you're copying code, you'll introduce a technical debt of double maintenance or more specifically: code duplication.
Usually this is fixed through refactoring. More specifically you redirect all the calls to a new function (or a new method in a new class) that has the common code. The easiest way to start is to remove all the copied code and see what breaks, in which you fix by redirecting the calls to the common code.
Getting your customer to agree to refactor code may be difficult since it is hard to convince a non-technical person to fix a technical debt. So the next time you give time estimates, just include the time it takes to refactor to your estimatesinclude the time it takes to refactor to your estimates. Most of the time customers do assume you're doing clean up of the code during the time you do the fix.