Implement TODOs from refactoring.

Also, functorize PrefixTable and begin refactoring
optimizations into PrefixTable.