Replaced usage of SortedSet with AvlTree