integrating test mode from prefix_tree. Debugged old code.