final refactor done. add jasmine tests