Added more tests and fixed a couple of bugs