Complete revision of traversal algorithm