added some tests and fixed a bug