Fix ast generation issue for CBN; code clean up