replace treemap with a balanced tree