Several bugs in trie implementation fixed

This fixes issue #37.
Also, several new trie-related unit tests are added.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>