updated code to handle the related items processing and the visitor
updates to handle the insert vs insert_replace.