Documentation, more tests, some refactoring