rewrite of binary tree