Changed merge to work recursively. Also replaced debugging output with more sensible error reporting.