Refactored, added jasmine tests and tweaked karma setup.