Fix range problems and use deepcopy for entities