Working typechecking with intermediate tree structure