Some refinements in type checking, a few bugs still