type checking algorithm