Simplify removeEmptyNodes