Fixed #4 - changed the detection method for top level nodes