added cloning to the extend function