Adding testcase for #1037
Refining testcase
Removing explicit template argument in testcase
Fixed issue with unwrap and shared state refcounting. Fixes #1037.