Tree handling for fast sorting and updating.