fix routing bugs, some optimization on trie