Implement typechecking for var and def declarations and refactor identifier typechecking
Add notes and comments