add unit tests and bugfixes.