Refactor for proper unit testing with karma, requirejs and angular.