Fixed a recursive deepcopy function that was massively slowing the program down