Key encoding fixed. Ancestors handling added.