Refactoring and merging redundant code in type checker.