refactored typechecker to use modules