rearchitected code to be more like an angularjs module