More improvements to type checking