Added some more tests and did some refactoring.