Refactored code, doing tests with  and  using the rootscope instead of using callbacks