#31, added some unit tests, some changes according to unit test results