Add some tests, fix a bug