Code overhaul to use a tries instead of hashtables