Use copy.deepcopy to avoid data corruption (#547)