refactor to used shared pointers