Replaced clone function to prevent circular reference problems