update some documentation
Add tests
fix bugs found by test