unit tests and some changes and fixes