more work on type system (nearly done)