Fix bug with PackWithReplacements when top-level object with complex objects.

PackWithReplacements failed with "Resources found during pickling",
because the original value becomes a Reference after replacemenet.
Merge pull request #227 from kennytm/top-level-pack-with-repl

Fix bug with PackWithReplacements when replacing top-level object with complex values.