fixes a problem with the variable endpoint not being clone each time the function is called