Many minor changes, some documentation, tests.