Fixing reference counting issues Dmytro and Rahul reported.
Merge pull request #7 from jhartman/master

Fixing reference counting issues Dmytro and Rahul reported.