fixed typo
reworked traverse function to save keys correctly