Added more tests, did some refactoring