add tests, some fixes