Update doc and remove some memory allocations.
Add tests.