fixed memory leaks with unique_ptr