added tests, lots of fixes, docs