resolving bug with double free corruption (smart pointer)