Simplify node traversal and fix IE where empty line has no children