Fix threading issue with cloning