reworked the whole Visitor class to allow transforming the tree through returning of new optional node and replacement inside the unique_ptr that was visiting on, everything seems to work