changed to use deep-copy. use more heap, but safe.