add tests and documentation; fix minor bugs