uses deepcopy to prevent mutation