add a few tests and fix a bug