Added more tests, fixed a bug