Implement merging of chains and graphs