Wrap dynamic allocations in smart pointer.

Replaced containers of pointer type with value type for safety.