fix the memory managing

* Add the nullptr using
* Minimize number of places where using the allocating and deallocating memory
* Add default init of class members