Add tests, improve documentation