Add sanity check to AVL tree, fix #597