add some unit tests, minor fix