Moved free(input) out of get_tree function