Added more tests and fixed bugs found