Deepcopy is changing algorythm behavior