add tests, bug fix