tree function implement.