Typed API fixes. Added more tests.