fix avl tree, change implementation to functional one