Added checking for invalid results in ast.