use OwningPtr and factor code better.