fixed minor memory leak by using shared_ptr