Implemented proper prefix tree with tests.