Fixed cloning function