fixed memory issue with shared_ptr