unit tests + bugfixes