Added more tests and fixed bugs in implementation