Refactor copyTree and add specs