add unit tests and bugfixing