Added more tests and a bugfix