Cleanup/Porting

Converte trie code to class.
Ported some helper function from pyhton to C++.