Some refactoring to the type checking of statements and expressions