Implement merge(), closes #3.

Handles cyclical references by throwing an error.