fix sorting
fix sorting
fix deep copy to work everywhere