Cleanup trie

this pull request fixes some possible problems and also contains formatting changes to trie.py