add deep copy functionality to matrices