optimazations; use copy instead of deepcopy