Typechecking function improvements

Please give the test suite a run before you merge this in.  I haven't gotten the chance to do so.