add forEach method to iterate over all nodes