Implementing merge and coalesce