nit: `nodeToSplit.mapValues(_.toSet).toMap` looks simpler to me