There's a lot to go through on this example... and many ways to handle such scenarios.
Personally, I very much like the HTABLE approach for "remembering" destinations. Instead of using a BYE to remove the entries, you might see if using DIALOG for this use case to be beneficial (removing the HTABLE entry when all calls are ended).
Depending on how the endpoints are linking attended transfers, you may need to consider adding SIP headers (like X-ORIG-CI) to add a call-id, from tag, or other info to identify original calls.
Again, many different ways that you could approach this, but sounds like you're on the right track for sure.
Fred Posner | palner.com Matrix: @fred:matrix.lod.com o: +1 (212) 937-7844