build tree recursively