add tests and fix #9