Ended code for tree mechanism