made traversal code more clear