Implement UniquePtr and use where appropriate.