adjust to add unit tests

Adding initial karma test, had to refactor to make tests readable.