Refactoring of merger.

Added complete parsing test (not passing yet).