add some tests, fix a bug