use ast_calloc instaed of calloc, and remove a couple of duplicated