Fix ByNested and unit tests