fix reference problem with define method + fix mergeJoins methods with cloning