tidy-up flatten_asts function and comment