Prevent unnecessary deep copying

As requested the pull request for #529