Check the semantic analysis phase and do some minor refactoring.