added traversing, changed output generation