code refactor, unique_ptr fix