Added jasmine for tests, added some tests, and refactored a bunch.