copy tree and count leaf nodes of tree