Improve error reporting in typechecker